package com.kobeliu.netty.http;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpServerCodec;

/**
 * 初始化器，channel注册后，会执行里面的相应的初始化方法
 */
public class HttpServerInitializer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {

        //管道负责信息传输
        //通过socketChannel获得对应的管道
        ChannelPipeline pipeline = socketChannel.pipeline();

        //通过管道添加handler
        //HttpServerCodec netty自己提供的，可以理解为拦截器
        //当请求到达服务端，需要做解码，响应给到客户端做编码
        //编解码的作用
        pipeline.addLast("HttpServerCodec",new HttpServerCodec());

        //注册添加的助手类，返回hello netty
        pipeline.addLast("HttpHandler",new HttpHandler());
    }
}
